package com.yan.edu.controller;


import com.google.common.annotations.GwtCompatible;
import com.yan.commonutils.R;
import com.yan.edu.entity.Course;
import com.yan.edu.entity.vo.CourseInfoVo;
import com.yan.edu.entity.vo.CoursePublishVo;
import com.yan.edu.service.CourseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-09-17
 */
@RestController
@RequestMapping("/edu/course")
@CrossOrigin
public class CourseController {
    @Autowired
    private CourseService courseService;

    @ApiOperation(value = "添加列表")
    @GetMapping
    public R getCourseList(){
        List<Course> list = courseService.list(null);
        return R.ok().data("list",list);
    }



//    添加课程基本信息
@ApiOperation(value = "添加课程基本信息")
    @PostMapping("addCourseInfo")
    public R addCourseInfo(@RequestBody CourseInfoVo courseInfoVo){
    String id = courseService.saveCourseInfo(courseInfoVo);

     return R.ok().data("courseId",id);
    }
    @ApiOperation(value = "根据id查询课程基本信息")
    @GetMapping("getCourseInfo/{courseId}")
    public R getCourseInfo(@PathVariable String courseId){
        CourseInfoVo courseInfoVo= courseService.getCourseInfo(courseId);
         return R.ok().data("courseInfoVo",courseInfoVo);

    }

    @ApiOperation(value = "修改课程基本信息")
    @PostMapping("updateCourseInfo")
        public R updateCourseInfo(@RequestBody CourseInfoVo courseInfoVo){
        courseService.updateCourseInfo(courseInfoVo);
              return R.ok();
        }
    //根据课程id查询课程确认信息
    @ApiOperation(value = "根据课程id查询课程确认信息")
    @GetMapping("getPublishCourseInfo/{id}")
    public R getPublishCourseInfo(@PathVariable String id) {
        CoursePublishVo coursePublishVo = courseService.publishCourseInfo(id);
        return R.ok().data("publishCourse",coursePublishVo);
    }
    @ApiOperation(value = "课程的最终发布")
    @PostMapping("publishCourse/{id}")
    public R publishCourse(@PathVariable String id){
        Course course = new Course();
        course.setId(id);
        course.setStatus("Normal");//设置课程的发布状态
        courseService.updateById(course);

        return R.ok();
    }
    @ApiOperation(value = "课程删除")
    @DeleteMapping("{courseId}")
    public R deleteCourse(@PathVariable String courseId){
        courseService.removeCourse(courseId);

        return R.ok();

    }


}

